#define _CRT_SECURE_NO_WARNINGS 1

/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};*/


class PalindromeList {
public:
    struct ListNode* reverseList(struct ListNode* head)
    {
        struct ListNode* newnode = NULL;
        struct ListNode* cur = head;
        while (cur)
        {
            struct ListNode* next = cur->next;
            cur->next = newnode;
            newnode = cur;
            cur = next;
        }
        return newnode;
    }

    struct ListNode* middleNode(struct ListNode* head)
    {
        struct ListNode* show = head;
        struct ListNode* fast = head;
        while (fast && fast->next)
        {
            show = show->next;
            fast = fast->next->next;
        }
        return show;
    }
    bool chkPalindrome(ListNode* head) {
        // write code here
        struct ListNode* mid = middleNode(head);
        struct ListNode* rmid = reverseList(mid);
        while (rmid)
        {
            if (head->val != rmid->val)
            {
                return false;
            }
            else {
                {
                    head = head->next;
                    rmid = rmid->next;
                }
            }
        }
        return true;
    }
};